#include <iostream>  
using namespace std;

struct Node {
    Node* left, * right;
    char data;
};
struct Node* change(struct Node* root)
{
    if (root == NULL)
        return NULL;
    struct Node* t;
    t = root->left;
    root->left = root->right;
    root->right = t;
    change(root->left);
    change(root->right);
    return root;
}
Node* dfs() {
    char x;
    cin >> x;
    if (x == '#') {
        return NULL;
    }
    else {
        Node* root = new Node();
        root->data = x;
        root->left = dfs();
        root->right = dfs();
        return root;
    }
}

void print(Node* root) {
    if (root == NULL) {
        return;
    }

    print(root->left);
    cout << root->data;
    print(root->right);
}

int main() {
    Node* root = dfs();
    print(root);
    root = change(root);
    cout << endl;
    print(root);
    return 0;
}